﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Style x:Key="Spinner" TargetType="{x:Type ProgressBar}">
        <Setter Property="IsIndeterminate" Value="True"/>

        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>

        <Setter Property="Width" Value="32px"/>
        <Setter Property="Height" Value="Auto"/>

        <Setter Property="MaxWidth" Value="{Binding Height, RelativeSource={RelativeSource Self}, FallbackValue=0}"/>
        <Setter Property="MaxHeight" Value="{Binding Width, RelativeSource={RelativeSource Self}, FallbackValue=0}"/>

        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="Background" Value="{x:Null}"/>
        <Setter Property="BorderBrush" Value="{x:Null}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <Viewbox VerticalAlignment="Stretch" HorizontalAlignment="Stretch" RenderTransformOrigin="0.5, 0.5">
                            <TextBlock Text="{DynamicResource fa-spinner}" FontFamily="{DynamicResource FontAwesome}"/>
                            <Viewbox.RenderTransform>
                                <RotateTransform/>
                            </Viewbox.RenderTransform>
                            <Viewbox.Triggers>
                                <EventTrigger RoutedEvent="Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetProperty="(Rectangle.RenderTransform).(RotateTransform.Angle)" To="360" Duration="0:0:1" RepeatBehavior="Forever"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Viewbox.Triggers>
                        </Viewbox>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>